package com.bay1ts.security;

import java.security.SecureRandom;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.web.authentication.rememberme.InMemoryTokenRepositoryImpl;
import org.springframework.security.web.authentication.rememberme.PersistentTokenBasedRememberMeServices;
import org.springframework.security.web.authentication.rememberme.PersistentTokenRepository;

public class CustomPersistentTokenBasedRememberMeServices extends PersistentTokenBasedRememberMeServices{
	@Autowired
	private PersistentTokenRepository tokenRepository;
	
	public PersistentTokenRepository getTokenRepository() {
		return tokenRepository;
	}

	public void setTokenRepository(PersistentTokenRepository tokenRepository) {
		this.tokenRepository = tokenRepository;
	}

	public CustomPersistentTokenBasedRememberMeServices(String key, UserDetailsService userDetailsService,
			PersistentTokenRepository tokenRepository) {
		super(key, userDetailsService, tokenRepository);
	}
	@Override
	public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
		// TODO Auto-generated method stub
		if (authentication != null) {
			tokenRepository.removeUserTokens(authentication.getName());
		}
	}

}
